package org.javacourse.service;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 * User: tania.luchin
 * Date: 4/11/13
 * Time: 4:03 PM
 * To change this template use File | Settings | File Templates.
 */
public class UtilService implements Serializable {

    private static final long serialVersionUID = -4570429616629760876L;
    protected static EntityManagerFactory emf = null;
    //TODO: initializarea statica a lui EntityManagerFactory
    //TODO: metoda getEntityManager trebuie sa fie statica


    public EntityManager getEntityManager() {
    if (UtilService.emf == null){
        createEntityManagerFactory();
    }
    return emf.createEntityManager();
    }


    private static void createEntityManagerFactory(){
        emf = Persistence.createEntityManagerFactory("firstJPA", System.getProperties());
    }

}


